asm
  ld sp,$DFFF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"
#include "./library/moguracharmap01.bas"
#include "./library/pacmanldir.bas"

dim eee as uinteger at $C010
dim seed as uinteger at $C012
dim ee1 as uinteger at $C014
dim ee2 as uinteger at $C016
dim ee3 as uinteger at $C018
dim ee4 as ubyte at $C01A
dim ecsp as ubyte at $C01C
dim ecsq as ubyte at $C01E
dim ex0 as uinteger at $C020
dim ey0 as uinteger at $C022
dim ex1 as uinteger at $C024
dim ey1 as uinteger at $C026
dim ex2 as uinteger at $C028
dim ey2 as uinteger at $C02A
dim ex3 as uinteger at $C02C
dim ey3 as uinteger at $C02E

sub moguraputchar(txp1 as uinteger,typ1 as uinteger,tch1 as ubyte,tat1 as ubyte):
  poke $F000+(typ1*64)+  ((txp1+16)mod 48)+16  ,tch1
  poke $F800+(typ1*64)+  ((txp1+16)mod 48)+16  ,tat1
  end sub

pacmanldir($E000+(32*16),@charmap01,1024)

for eee=0 to 63
  poke $E000+eee,%01010101*(int(eee/16))
  next

seed=0

for ee1=0 to 31
  for ee2=0 to 39
    seed=smsrnd(seed):ee3=seed:seed=smsrnd(seed)
    moguraputchar(ee2+0,ee1+0,seed band 3, (ee3 band 7)*2  )
    'pacmandelay(1000)
    next:next

for ee1=0 to 15
  for ee2=0 to 15
    moguraputchar(ee2+23,ee1+15, ee1*16+ee2 ,0  )
    next:next

ex0=12:ey0=6
ex1=12:ey1=12
ex2=12:ey2=18
ex3=12:ey3=24
eee=0
do
  moguraputchar(1,1,48+(int(eee/100) mod 10),0)
  moguraputchar(2,1,48+(int(eee/10) mod 10),0)
  moguraputchar(3,1,48+(eee mod 10),0)

  ee1=in($08) bxor 255
  moguraputchar(1,3,48+(int(ee1/100) mod 10),0)
  moguraputchar(2,3,48+(int(ee1/10) mod 10),0)
  moguraputchar(3,3,48+(ee1 mod 10),0)

  ee1=in($0C) bxor 255
  moguraputchar(1,4,48+(int(ee1/100) mod 10),0)
  moguraputchar(2,4,48+(int(ee1/10) mod 10),0)
  moguraputchar(3,4,48+(ee1 mod 10),0)

  ex0=ex0-((ee1 band 1)/1)+((ee1 band 2)/2)
  ey0=ey0-((ee1 band 4)/4)+((ee1 band 8)/8)
  moguraputchar(ex0,ey0,(eee band 63)+32,2)




  ee1=in($0D) bxor 255
  moguraputchar(1,5,48+(int(ee1/100) mod 10),0)
  moguraputchar(2,5,48+(int(ee1/10) mod 10),0)
  moguraputchar(3,5,48+(ee1 mod 10),0)

  ex1=ex1-((ee1 band 1)/1)+((ee1 band 2)/2)
  ey1=ey1-((ee1 band 4)/4)+((ee1 band 8)/8)
  moguraputchar(ex1,ey1,(eee band 63)+32,4)



  ee1=in($0E) bxor 255
  moguraputchar(1,6,48+(int(ee1/100) mod 10),0)
  moguraputchar(2,6,48+(int(ee1/10) mod 10),0)
  moguraputchar(3,6,48+(ee1 mod 10),0)

  ex2=ex2-((ee1 band 1)/1)+((ee1 band 2)/2)
  ey2=ey2-((ee1 band 4)/4)+((ee1 band 8)/8)
  moguraputchar(ex2,ey2,(eee band 63)+32,6)



  ee1=in($0F) bxor 255
  moguraputchar(1,7,48+(int(ee1/100) mod 10),0)
  moguraputchar(2,7,48+(int(ee1/10) mod 10),0)
  moguraputchar(3,7,48+(ee1 mod 10),0)

  ex3=ex3-((ee1 band 1)/1)+((ee1 band 2)/2)
  ey3=ey3-((ee1 band 4)/4)+((ee1 band 8)/8)
  moguraputchar(ex3,ey3,(eee band 63)+32,8)



  ee1=in($10) bxor 255
  moguraputchar(1,8,48+(int(ee1/100) mod 10),0)
  moguraputchar(2,8,48+(int(ee1/10) mod 10),0)
  moguraputchar(3,8,48+(ee1 mod 10),0)


  eee=eee+1
  pacmandelay(1000)
  loop


'- AM_RANGE(0x08, 0x08) AM_READ_PORT("SYSTEM")
'- AM_RANGE(0x0c, 0x0c) AM_READ_PORT("P1")
'- AM_RANGE(0x0d, 0x0d) AM_READ_PORT("P2")
'- AM_RANGE(0x0e, 0x0e) AM_READ_PORT("P3")
'- AM_RANGE(0x0f, 0x0f) AM_READ_PORT("P4")
'- AM_RANGE(0x10, 0x10) AM_READ_PORT("SERVICE")



'-----------------------------------------------------------


for eee=$E000 to $FFFF
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(10000)
  next



do
loop



for eee=$E000 to $E7FF
  seed=smsrnd(seed)
  poke eee,seed
  next

for eee=$E800 to $EFFF
  seed=smsrnd(seed)
  poke eee,seed
  next


for eee=$F000 to $F7FF
  seed=smsrnd(seed)
  poke eee,seed
  next

for eee=$F800 to $FFFF
  seed=smsrnd(seed)
  poke eee,seed
  next



do:loop

'------------------------------------------------------------------------------

ch01:
asm
  defb %00001111,%11000000
  defb %00111100,%11110000
  defb %11110000,%00111100
  defb %11110000,%00111100

  defb %11111111,%11111100
  defb %11110000,%00111100
  defb %11110000,%00111100
  defb %00000000,%00000000

  end asm


